package com.mm.fam.web.base;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

public class ResponseUtil {
	public static <T> ResponseEntity<ResponseModel<T>> success(T t) {
		ResponseModel<T> rm = new ResponseModel<>();
		rm.setCode(200);
		rm.setData(t);
		rm.setMsg("OK");
		return new ResponseEntity<>(rm, HttpStatus.OK);
	}

	public static <T> ResponseEntity<ResponseModel<T>> success(String msg) {
		ResponseModel<T> rm = new ResponseModel<>();
		rm.setCode(200);
		rm.setMsg(msg);
		return new ResponseEntity<>(rm, HttpStatus.OK);
	}

	public static <T> ResponseEntity<ResponseModel<T>> success(T t, String msg) {
		ResponseModel<T> rm = new ResponseModel<>();
		rm.setCode(200);
		rm.setData(t);
		rm.setMsg(msg);
		return new ResponseEntity<>(rm, HttpStatus.OK);
	}

	public static <T> ResponseEntity<ResponseModel<T>> fail(Integer code, String msg){
		ResponseModel<T> rm = new ResponseModel<>();
		rm.setCode(code);
		rm.setMsg(msg);
		return new ResponseEntity<>(rm, HttpStatus.OK);
	}

	public static <T> ResponseEntity<ResponseModel<T>> fail(String msg){
		ResponseModel<T> rm = new ResponseModel<>();
		rm.setCode(230);
		rm.setMsg(msg);
		return new ResponseEntity<>(rm, HttpStatus.OK);
	}

	public static <T> ResponseEntity<ResponseModel<T>> error(String msg) {
		ResponseModel<T> rm = new ResponseModel<>();
		rm.setCode(500);
		rm.setMsg(msg);
		return new ResponseEntity<>(rm, HttpStatus.INTERNAL_SERVER_ERROR);
	}
}
